package com.aididi;

import com.aididi.factory.Receiver;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @Auther: zx.xu
 * @Description:
 */
@Component
@Slf4j
@Setter(onMethod = @_({@Autowired}))
public class Runner implements CommandLineRunner {

    private final RabbitTemplate rabbitTemplate;
    private final Receiver receiver;

    public Runner(Receiver receiver,RabbitTemplate rabbitTemplate) {
        this.receiver = receiver;
        this.rabbitTemplate = rabbitTemplate;
    }


    @Override
    public void run(String... args) throws Exception {
        log.info("send message..");
        rabbitTemplate.convertAndSend(RabbitmqMessageQueueApplication.exchangeName,"foo.bar.baz","hello rabbitmq queue");
        receiver.getCount().await(10000, TimeUnit.SECONDS);
    }
}
